unit ELkGroup;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, ExtCtrls, StdCtrls, Buttons, FMTBcd, DB,
  DBClient, Provider, SqlExpr, DbZoom, ZAbstractRODataset,
  ZAbstractDataset, ZDataset;

type
  TfmLkGroup = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    dgDetail: TDbGridZoomT;
    edSearch: TEdit;
    lblValue: TLabel;
    btSearch: TBitBtn;
    GroupBox1: TGroupBox;
    rbCode: TRadioButton;
    rbName: TRadioButton;
    btOK: TBitBtn;
    btCancel: TBitBtn;
    dsLk: TDataSource;
    ckPart: TCheckBox;
    qrLk: TZQuery;
    qrLang: TZReadOnlyQuery;
    procedure btSearchClick(Sender: TObject);
    procedure dgDetailKeyPress(Sender: TObject; var Key: Char);
    procedure dgDetailDblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
    procedure changcaption;
  public
    { Public declarations }
  end;

var
  fmLkGroup: TfmLkGroup;

implementation
uses dmIdocqment,Utility;

{$R *.dfm}

procedure TfmLkGroup.btSearchClick(Sender: TObject);
var sqlCom,sSearch,fn,lk,lkb,sorder_:string;
begin
  with qrLk do
  begin
    if active then close;
    sSearch:=trim(edSearch.text);
    //--for override descentant;
    fn:='name';
    if rbCode.checked then fn:='id';

    sorder_:=' order by '+fn;
    if rbCode.checked then sorder_:=' order by '+fn;

    lk:=' like '+sq_;  lkb:='%'+sq_;
    if ckPart.checked then
    begin
      lk:=lk+'%';
    end ;
    if sSearch='' then sqlCom:=format(sl,['*','depart']) else
      sqlCom:=format(sql2,['depart',fn+' '+lk +sSearch +lkb]);

    //--new open dataset alway;
    qrLk.sql.clear;
    qrLk.sql.add(sqlCom + sorder_);
    open;
  end;
end;

procedure TfmLkGroup.dgDetailKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then btOK.click;
end;

procedure TfmLkGroup.dgDetailDblClick(Sender: TObject);
begin
  btOK.click;
end;

procedure TfmLkGroup.FormCreate(Sender: TObject);
begin
  with qrLk do
  begin
    close;
    open;
  end;
  changcaption;
end;

procedure TfmLkGroup.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key=VK_Escape then btCancel.click;
end;

procedure TfmLkGroup.changcaption;
begin
  with qrLang do
  begin
    close;
    parambyname('lang').asstring:=dm.languagedef;
    open;
    lblValue.caption:=Get2Caption(qrLang,'C003','Value');
    ckPart.caption:=Get2Caption(qrLang,'C004','Partial');
    btSearch.caption:=Get2Caption(qrLang,'C005','Search');
    GroupBox1.caption:=Get2Caption(qrLang,'C008','Option');
    rbName.caption:=Get2Caption(qrLang,'C002','Description');
    rbCode.caption:=Get2Caption(qrLang,'C001','ID');
  end;
  with dgDetail do
  begin
    columns[0].Title.caption:=rbCode.caption;
    columns[1].Title.caption:=rbName.caption;
  end;
  btOK.caption:=Get2Caption(qrLang,'C006','OK');
  btCancel.caption:=Get2Caption(qrLang,'C007','Cancel');
end;

end.
